package cn.sweet.config;

import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * 设置界面
 *
 * @author wellhor Zhao
 * @version 1.0
 * @date 2021/11/24 4:50 下午
 **/
public class AppSettingsComponent {

    private final JPanel myMainPanel;

    private final static String USER_NAME_LABEL = "用户名/uerName: ";

    private final static String TIME_LABEL = "时间格式/SimpleDateFormat (例如 yyyy-MM-dd HH:mm:ss): ";

    private final static String USER_ANNOTATION_LABEL = "用户名注释/UserAnnotation (例如 @LastEditorPerson): ";

    private final static String TIME_ANNOTATION_LABEL = "时间注释/TimeAnnotation (例如 @LastEditorTime): ";

    private final static String FILE_WATCHED_LABEL = "需要监控的文件后缀/Monitored File Suffix (多个格式空格隔开 例如 .js .vue .java): ";

    private final static String MAX_LINE_COUNT_LABEL = "请输入最大监控行数/Max Monitored Line Number (默认值 15): ";

    private final static String IS_CHANGE_LABEL = "是否每次更改都修改注释头/Whether to modify the comment header for every change: ";

    private final JBTextField myUserNameText = new JBTextField();

    private final JBTextField myTimeFormatText = new JBTextField();

    private final JBTextField myEditPersonText = new JBTextField();

    private final JBTextField myEditTimeText = new JBTextField();

    private final JBTextField mySuffixText = new JBTextField();

    private final JBTextField maxLineCountText = new JBTextField();

    private final JBCheckBox isAnyChange = new JBCheckBox(IS_CHANGE_LABEL);

    public AppSettingsComponent() {
        myMainPanel = FormBuilder.createFormBuilder()
                .addLabeledComponent(new JBLabel(USER_NAME_LABEL), myUserNameText, 1, false)
                .addLabeledComponent(new JBLabel(TIME_LABEL), myTimeFormatText, 1, false)
                .addLabeledComponent(new JBLabel(USER_ANNOTATION_LABEL), myEditPersonText, 1, false)
                .addLabeledComponent(new JBLabel(TIME_ANNOTATION_LABEL), myEditTimeText, 1, false)
                .addLabeledComponent(new JBLabel(FILE_WATCHED_LABEL), mySuffixText, 1, false)
                .addLabeledComponent(new JBLabel(MAX_LINE_COUNT_LABEL), maxLineCountText, 1, false)
                .addComponent(isAnyChange, 1)
                .addComponentFillVertically(new JPanel(), 0)
                .getPanel();
    }

    public JPanel getPanel() {
        return myMainPanel;
    }

    public JComponent getPreferredFocusedComponent() {
        return myUserNameText;
    }

    public String getUserNameText() {
        return myUserNameText.getText();
    }

    public void setUserNameText(@NotNull String newText) {
        myUserNameText.setText(newText);
    }

    public String getTimeFormat() {
        return myTimeFormatText.getText();
    }

    public void setTimeFormat(@NotNull String newText) {
        myTimeFormatText.setText(newText);
    }

    public String getLastEditPersonText() {
        return myEditPersonText.getText();
    }

    public void setLastEditPersonText(@NotNull String newText) {
        myEditPersonText.setText(newText);
    }

    public String getLastTimeText() {
        return myEditTimeText.getText();
    }

    public void setLastTimeText(@NotNull String newText) {
        myEditTimeText.setText(newText);
    }

    public String getSuffix() {
        return mySuffixText.getText();
    }

    public void setSuffix(@NotNull String newText) {
        mySuffixText.setText(newText);
    }

    public String getMaxLineCountText() {
        return maxLineCountText.getText();
    }

    public void setMaxLineCountText(@NotNull String nexText) {
        maxLineCountText.setText(nexText);
    }

    public boolean getIsAnyChange() {
        return isAnyChange.isSelected();
    }

    public void setIsAnyChange(boolean newStatus) {
        isAnyChange.setSelected(newStatus);
    }
}
